package com.collection.treemaps;

import java.util.Collection;
import java.util.Iterator;
import java.util.TreeMap;

public class IterateValuesOfTreeMapExample {
	public static void main(String[] args) {
		   
	    //create TreeMap object
	    TreeMap treeMap = new TreeMap();
	   
	    //add key value pairs to TreeMap
	    treeMap.put("1","One");
	    treeMap.put("2","Two");
	    treeMap.put("3","Three");
	   
	    /*
	      get Collection of values contained in TreeMap using
	      Collection values() method of TreeMap class
	    */
	    Collection c = treeMap.values();
	   
	    //obtain an Iterator for Collection
	    Iterator itr = c.iterator();
	   
	    //iterate through TreeMap values iterator
	    while(itr.hasNext())
	      System.out.println(itr.next());
	  }
}
